package com.abbcc.module.admin;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;

import com.abbcc.action.BaseAction;
import com.abbcc.models.TdProduct;
import com.abbcc.models.TdRecycle;
import com.abbcc.service.RecycleService;

public class RecycleAction extends BaseAction<TdRecycle>{
	@Autowired
	private RecycleService recycleService;
	
	@SuppressWarnings("unchecked")
	public String list(){
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		dc.addOrder(Order.desc("delTime"));
		pageList = recycleService.findPageByCriteria(dc, pageSize, startIndex);
		//stepName((TdRecycle[])pageList.getItems().toArray(new TdRecycle[0]));
		return LIST;
	}
	public String del(){
		recycleService.load(entity, entity.getRecycleId());
		recycleService.delete(entity);
		result = "删除成功!";
		return list();
	}
	public String reduct(){
		recycleService.load(entity, entity.getRecycleId());
		TdProduct td = new TdProduct();
		baseService.load(td, entity.getBelongId());
		td.setState("1");
		baseService.update(td);
		recycleService.delete(entity);
		result = "还原成功!";
		return list();
		
	}
	/*private void stepName(TdRecycle... recycles){
		for(TdRecycle tr:recycles){
			tr.set
		}
	}*/
}
